package client.window;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Map;

import surname.protocol.ListSurnameRequest;

public class ListenerMenuList implements ActionListener
{
	MainFrame mf;
	
	public ListenerMenuList(MainFrame mf)
	{
		this.mf = mf;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) 
	{
		Map<String, List<String>> map;
		mf.remove(mf.getMainPanel());
		mf.remove(mf.getListSurnamePanel());
		mf.remove(mf.getEditSurnamePanel());
		mf.remove(mf.getListSurnamePanel());
		ListSurnameRequest request = new ListSurnameRequest();
		if(mf.getClient().getE().send(request))
		{
			mf.getText().append("Requete envoyée");
		}
		else
		{
			mf.getText().append("Echec lors de l'envoi de la requete");
		}
		map = mf.getClient().getR().get();
		System.out.println(map);
		mf.getList().setText("");
		for(String s : map.keySet())
		{
			List<String> li = map.get(s);
			mf.getList().append(s + " :");
			for(String surnom : li)
			{
				mf.getList().append(" " + surnom + ",");
			}
			mf.getList().append("\n");
		}
		mf.add(mf.getListSurnamePanel());
		mf.validate();
		mf.repaint();
	}

}